package src.week5.SHIYAN3;

import junit.framework.TestCase;

public class StringBufferDemoTest extends TestCase {
    StringBuffer a = new StringBuffer("wanglaoshitaiqiangle");
    StringBuffer b = new StringBuffer("zhujiaoyehenqiang");
    StringBuffer c = new StringBuffer("wotaicaile555");

    public void testcharAt(){                    //字符索引测试
        assertEquals('w',a.charAt(0));
        assertEquals('o',b.charAt(6));
        assertEquals('5',c.charAt(10));
    }

    public void testcapacity(){                  //测试caoacity(),发现其返回的数值是length()+16
        assertEquals(36,a.capacity());
        assertEquals(33,b.capacity());
        assertEquals(29,c.capacity());
    }

    public void testlength(){                    //字符串长度测试
        assertEquals(20,a.length());
        assertEquals(17,b.length());
        assertEquals(13,c.length());
    }

    public void testindexOf(){                   //子串匹配测试
        assertEquals(0,a.indexOf("wanglaoshi"));
        assertEquals(3,b.indexOf("jiao"));
        assertEquals(10,c.indexOf("555"));
    }
}
